package com.czy.daishusys.adapter;

import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.czy.daishusys.R;
import com.czy.daishusys.entity.HomeOrderModel;
import com.czy.daishusys.utils.GsonUtils;
import com.czy.daishusys.utils.glide.GlideUtils;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by asus on 2017/11/30.
 */

public class HomeOrderItemAdapter extends BaseQuickAdapter<HomeOrderModel.DataBean.ListBean.OrderItemsBean, BaseViewHolder> {
    public HomeOrderItemAdapter(int layoutResId, @Nullable List<HomeOrderModel.DataBean.ListBean.OrderItemsBean> data) {
        super(layoutResId, data);
    }

    private ImageView ivOrderGoodsImg;

    @Override
    protected void convert(BaseViewHolder holder, HomeOrderModel.DataBean.ListBean.OrderItemsBean item) {
        holder.setText(R.id.tv_order_goods_name, item.getItemName())
                .setText(R.id.tv_order_goods_sale, "¥" + String.format("%.2f", item.getPrice()))
                .setText(R.id.tv_order_goods_origin, "¥" + String.format("%.2f", item.getGoodsSpecValuesPrice()))
                .setText(R.id.tv_order_goods_standard, (TextUtils.isEmpty(item.getSpecValue()) || "规格:无规格".equals(item.getSpecValue())) ? "" : item.getSpecValue())
                .setText(R.id.tv_order_goods_count, "x" + item.getCount());
        ivOrderGoodsImg = (ImageView) holder.getView(R.id.iv_order_goods_img);
        GlideUtils.loadImage(mContext, item.getLogo(),ivOrderGoodsImg, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
            @Override
            public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

            }

            @Override
            public void onLoadingError(String source, Exception e) {
                ivOrderGoodsImg.setImageResource(R.mipmap.icon_goods_list_default);
            }
        });
        ((TextView) holder.getView(R.id.tv_order_goods_origin)).getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        TextView tvOrderInstallationCost = (TextView) holder.getView(R.id.tv_order_installation_cost);
        if (item.getNeedService()) {
            tvOrderInstallationCost.setText("安装费: ¥" + String.format("%.2f", item.getServicePrice()));
        } else {
            tvOrderInstallationCost.setVisibility(View.INVISIBLE);
        }
    }
}
